package com.trt.eatmeat.controller;

import com.trt.eatmeat.socket.HttpMsg;
import com.trt.eatmeat.socket.MsgData;
import com.trt.eatmeat.socket.UserChannelRel;
import com.trt.eatmeat.util.*;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Author yufeng_ma@trtjk.com
 * @Description //TODO
 * @Date 2022/1/18 17:40
 **/
@RestController
public class AppTestController {


    @RequestMapping(value = "/test", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    ResponseData<String> test(){
        ResponseData<String>  responseData = new ResponseData<>();
        MsgData msgData = new MsgData();
        msgData.set_reqNo(UUID.randomUUID().toString());
        msgData.set_sendId("001");
        msgData.set_receiptId("001");
        msgData.set_type(MsgType.http.getName());
        HttpMsg msg = new HttpMsg();
        msg.setUrl(ContantUtils.login);
        msg.setMethod(HttpMethonType.post.getName());
        msg.setAlias(ContantUtils.login);
        msg.setHeaders(null);
        Map<String,Object> param = new HashMap<>();
        param.put("loginid","yufeng_ma");
        param.put("userpassword","Aa123456");
        param.put("logintype","1");
        param.put("isie","false");
        msg.setParam(param);
        msgData.set_jsonMsg(msg);
        UserChannelRel.get(msgData.get_sendId()).writeAndFlush(Unpooled.copiedBuffer(JsonUtils.objectToJson(msgData), CharsetUtil.UTF_8));
        return responseData.success("hello");
    }

    @RequestMapping(value = "/test2", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    ResponseData<String> test2(){
        ResponseData<String>  responseData = new ResponseData<>();
        MsgData msgData = new MsgData();
        msgData.set_sendId("001");
        msgData.set_reqNo(UUID.randomUUID().toString());
        msgData.set_receiptId("001");
        msgData.set_type(MsgType.http.getName());
        HttpMsg msg = new HttpMsg();
        msg.setUrl(ContantUtils.subscript);
        msg.setMethod(HttpMethonType.get.getName());
        msg.setAlias(ContantUtils.subscript);
        msg.setHeaders(null);
        Map<String,Object> param = new HashMap<>();
        param.put("jsondata","[{\"date\":\"2022-01-29\",\"userid\":4564,\"type\":0,\"val\":1}]"); // 早餐取消
        param.put("jsondata","[{\"date\":\"2022-01-29\",\"userid\":4564,\"type\":0,\"val\":0}]"); // 早餐预约

        param.put("jsondata","[{\"date\":\"2022-01-30\",\"userid\":4564,\"type\":1,\"val\":1}]"); // 午餐取消
        param.put("jsondata","[{\"date\":\"2022-01-30\",\"userid\":4564,\"type\":1,\"val\":0}]"); // 午餐预约

        msg.setParam(param);
        msgData.set_jsonMsg(msg);
        UserChannelRel.get(msgData.get_sendId()).writeAndFlush(Unpooled.copiedBuffer(JsonUtils.objectToJson(msgData), CharsetUtil.UTF_8));
        return responseData.success("hello");
    }

}
